<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 1] 1.3 Java Compared</TITLE>
<META NAME="author" CONTENT="Pat Niemeyer and Josh Peck">
<META NAME="date" CONTENT="Tue Jul 22 18:47:17 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Exploring Java">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Exploring Java" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 1<br>Yet Another Language?</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch01_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="EXJ-CH-1-SECT-3">1.3 Java Compared</A></h2>

<P CLASS=para>
Java is a new language, but it draws on many years of programming
experience with other languages in its choice of features. So a lot
can be said in comparing and contrasting Java with other
languages. There are at least three pillars necessary to support a
universal language for network programming today: portability, speed,
and security. <A HREF="ch01_03.htm#EXJ-CH-1-FIG-2">Figure 1.2</A> shows how Java
compares to other languages.

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="EXJ-CH-1-FIG-2">Figure 1.2: Programming languages compared</A></h4>


<p>
<img align=middle src="./figs/je0102.gif" alt="[Graphic: Figure 1-2]" width=503 height=203 border=0>

</DIV>

<P CLASS=para>
You may have heard that Java is a lot like C or C++, but
that's really not true, except at a superficial level. When you
first look at Java code, you'll see that the basic syntax looks
a lot like C or C++. But that's where the similarities end. Java
is by no means a direct descendant of C or a next generation C++. If
you compare language features, you'll see that Java actually has
more in common with languages like Smalltalk and Lisp. In fact,
Java's implementation is about as far from native C as you can
imagine.

<P CLASS=para>
The surface-level similarities to C and C++ are worth noting,
however.  Java borrows heavily from C and C++ syntax, so you'll
see lots of familiar language constructs, including an abundance of
curly braces and semicolons. Java also subscribes to the C philosophy
that a good language should be compact; in other words, it should be
sufficiently small and regular so that a programmer can hold all
the language's capabilities in his or her head at once. As C is
extensible with libraries, packages of Java classes can be added
to the core language components.

<P CLASS=para>
C has been successful because it provides a reasonably
featureful programming environment, with high performance and an
acceptable degree of portability.  Java also tries to balance
functionality, speed, and portability, but it does so in a very
different way. While C trades functionality to get portability,
Java trades speed for portability. Java also addresses security
issues, while C doesn't.

<P CLASS=para>
Java is an interpreted language, so it won't be as
fast as a compiled language like C. But Java is fast enough,
especially for interactive, network-based applications, where the
application is often idle, waiting for the user to do something or
waiting for data from the network. For situations where speed is
critical, a Java implementation can optimize performance by compiling
byte-code to native machine code on the fly.

<P CLASS=para>
Scripting languages, like Tcl, Perl, and Wksh, are becoming quite
popular, and for good reason. There's no reason a scripting
language could not be suitable for safe, networked applications (e.g.,
Safe Tcl), but most scripting languages are not designed for serious,
large-scale programming. The attraction to scripting languages is that
they are dynamic; they are powerful tools for rapid prototyping. Some
scripting languages, like awk and Perl, also provide powerful tools
for text-processing tasks more general-purpose languages find
unwieldy. Scripting languages are also highly portable.

<P CLASS=para>
One problem with scripting languages, however, is that they are
rather casual about program structure and data typing. Most scripting
languages (with a hesitant exception for Perl 5.0) are not object
oriented. They also have vastly simplified type systems and generally
don't provide for sophisticated scoping of variables and
functions. These characteristics make them unsuitable for building
large, modular applications. Speed is another problem with scripting
languages; the high-level, fully interpreted nature of these languages
often makes them quite slow.

<P CLASS=para>
Java offers some of the essential advantages of a scripting
language, along with the added benefits of a lower-level
language.[1] 
 Incremental development with object-oriented components, combined
with Java's simplicity, make it possible to develop applications
rapidly and change them easily, with a short concept to implementation
time. Java also comes with a large base of core classes for common
tasks such as building GUIs and doing network
communications. But along with these features, Java has the
scalability and software-engineering advantages of more static
languages. It provides a safe structure on which to build higher-level
networked tools and languages.

<blockquote class=footnote>
<P CLASS=para>[1] 
Don't confuse Java with JavaScript. JavaScript is an
object-based scripting language being developed by
Netscape and is designed to create dynamic, interactive Web
applications. JavaScript is a very different language from Java in
most respects. For more information on JavaScript, check out
Netscape's Web site
(<A HREF="http://home.netscape.com">http://home.netscape.com</A>).
</blockquote>
<P CLASS=para>
As I've already said, Java is similar in
design to languages like Smalltalk and Lisp. However, these languages
are used mostly as research vehicles, rather than for developing
large-scale systems. One reason is that they never developed a
standard portable binding to operating-system services analogous to
the C standard library or the Java core classes.  Smalltalk is
compiled to an interpreted byte-code format, and it can be dynamically
compiled to native code on the fly, just like Java. But Java improves
on the design by using a byte-code verifier to ensure the correctness
of Java code. This verifier gives Java a performance advantage over
Smalltalk because Java code requires fewer run-time
checks. Java's byte-code verifier also helps with security
issues, something that Smalltalk doesn't address. Smalltalk is a
mature language though, and Java's designers took lessons from many
of its features.

<P CLASS=para>
Throughout the rest of this chapter, we'll take a
bird's eye view of the Java language. I'll explain
what's new and what's not so new about Java; how it
differs from other languages, and why.

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch01_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>A Virtual Machine</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Safety of Design</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
